﻿using Lg.Core.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lg.Core.Form.Types
{
    public class Image : BaseType, IType
    {
        /// <summary>
        /// 上传最大尺寸限制
        /// </summary>
        public int MaxSize { get; set; }
        /// <summary>
        /// 允许的文件类型
        /// </summary>
        public List<string?>? FileTypes { get; set; }
        /// <summary>
        /// 文件上传数量
        /// </summary>
        public int? FileCount { get; set; }
        public void Verify()
        {
            if (this.IsRender)
            {
                if (Required)
                {
                    try
                    {
                        var arry = this.Value?.ToList<string>();
                        if (arry.Count == 0)
                        {
                            throw new Exceptions.LgException("请上传文件！");
                        }
                    }
                    catch
                    {
                        throw new Exceptions.LgException("内容格式不正确，无法解析！");
                    }
                }
            }

        }

        public void GetSaveDbValue(Dictionary<string, dynamic> formData, string inputValue)
        {
            formData.Add(Name, inputValue);
        }
        
    }
}
